package com.yu.blog.utils;

import java.util.Random;
import java.util.UUID;

public class RandomUtils {

    /**
     * 随机生成六位数字验证码
     */
    public static String randomSixCode() {
        return String.valueOf(new Random().nextInt(899999) + 100000);
    }

    /**
     * 生成UUID
     */
    public static String randomStrUUID(boolean isWhole) {
        return isWhole ? UUID.randomUUID().toString() : UUID.randomUUID().toString().replaceAll("-", "");
    }

    /**
     * 随机生成x位数字或字母验证码
     */
    public static String randomLetterCode(int x){
        String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
        StringBuilder buffer=new StringBuilder();
        int len=str.length()-1;
        for (int i=0;i<x;i++){
            buffer.append(str.charAt(new Random().nextInt(len+1)));
        }
        return buffer.toString();
        }

    /**
     * 将随机字符串的字母转化为大写
     */
    public static String letterUpperCase(String x){
        StringBuilder buffer=new StringBuilder();
        for (int i = 0; i < x.length(); i++) {
            char ch=x.charAt(i);
            if(ch>='a'&&ch<='z'){
                ch=(char)((int)ch-32);
            }
            buffer.append(ch);
        }
        return buffer.toString();
    }

}
